package com.lb.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @ClassName CallableDemo
 * @Author LB
 * @Date 2021/12/24 10:43
 **/
public class CallableDemo implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName() + "开始随机数...");
        int i = ThreadLocalRandom.current().nextInt(10);
        return 10;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallableDemo callableDemo = new CallableDemo();
        FutureTask<Integer> task = new FutureTask<Integer>(callableDemo);
        new Thread(task).start();
        System.out.println(task.isDone());
        Integer result = task.get();
        System.out.println(result);
    }
}